package cn.whale.rag;

import dev.langchain4j.data.segment.TextSegment;
import dev.langchain4j.store.embedding.EmbeddingStore;
import dev.langchain4j.store.embedding.pgvector.PgVectorEmbeddingStore;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 嵌入模型配置
 */
@Configuration
@RequiredArgsConstructor
public class EmbeddingStoreConfig {


    final PgConfig pgConfig;

	//创建向量存储
    @Bean
    public EmbeddingStore<TextSegment> initEmbeddingStore() {
		//基于 PgVector的向量存储 - 基于yml配置读取
        return PgVectorEmbeddingStore.builder()
            .table(pgConfig.getTable())
            //.dropTableFirst(true) 每次重启都要重新创建
            .createTable(true)	//自动创建表
            .host(pgConfig.getHost())
            .port(pgConfig.getPort())
            .user(pgConfig.getUser())
            .password(pgConfig.getPassword())
            .dimension(384)	//all-minilm模型的向量维度(简单理解就是内容长度如[111,222 ... 333])
            .database(pgConfig.getDatabase())
            .build();
    }
}

